package com.xzq.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
/**
 * 商品实体类
 * @author Adam
 *
 */
@Entity
public class Product implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer id;
	@Column(length=50,nullable=false)
	private String name;
	@Column(length=255)
	private String note;
	@Column
	private Integer stock;
	@Column
	private Double price;
	@Column
	private Timestamp addDate;
	@Column(length=100)
	private String img;
	@ManyToOne(cascade={CascadeType.MERGE},fetch=FetchType.EAGER)
	@JoinColumn(name="type_id")
	private Type type;
	@OneToMany(cascade={CascadeType.MERGE},fetch=FetchType.LAZY)
	@JoinColumn(name="product_id",insertable=true)
	private Set<OrderAndProduct> onps = new HashSet<OrderAndProduct>();
	
	public String getImg() {
		return img;
	}
	public void setImg(String img) {
		this.img = img;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNote() {
		return note;
	}
	public void setNote(String note) {
		this.note = note;
	}
	public Integer getStock() {
		return stock;
	}
	public void setStock(Integer stock) {
		this.stock = stock;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	
	public Timestamp getAddDate() {
		return addDate;
	}
	public void setAddDate(Timestamp addDate) {
		this.addDate = addDate;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public Set<OrderAndProduct> getOnps() {
		return onps;
	}
	public void setOnps(Set<OrderAndProduct> onps) {
		this.onps = onps;
	}
	public Product() {
		super();
	}

	public Product(String name, String note, Integer stock, Double price,
			Timestamp addDate, String img) {
		super();
		this.name = name;
		this.note = note;
		this.stock = stock;
		this.price = price;
		this.addDate = addDate;
		this.img = img;
	}
	public Product(Integer id, String name, String note, Integer stock,
			Double price, Timestamp addDate, String img) {
		super();
		this.id = id;
		this.name = name;
		this.note = note;
		this.stock = stock;
		this.price = price;
		this.addDate = addDate;
		this.img = img;
	}
	@Override
	public String toString() {
		return "Product [id=" + id + ", name=" + name + ", note=" + note
				+ ", stock=" + stock + ", price=" + price + ", addDate="
				+ addDate + "]";
	}
	
}
